package com.lagou;

import com.lagou.bean.ConsumerComponent;
import com.lagou.config.AppConfig;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author bobcheng
 * @date 2020/6/16
 */
public class ConsumerMain {

    private static final ExecutorService RPC_EXECUTOR = new ScheduledThreadPoolExecutor(5, new BasicThreadFactory.Builder().namingPattern("rpcExecutor-pool-%d").daemon(true).build());

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        context.start();
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        while (true) {
            Thread.sleep(1000);
            RPC_EXECUTOR.submit(()-> {
                try {
                    service.testA();
                    service.testB();
                    service.testC();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
